package com.wlcj.www.model.platform;

import java.util.List;

import com.jfinal.plugin.activerecord.Model;
import com.wlcj.util.CacheKeyUtil;
import com.wlcj.util.RedisUtil;
import com.wlcj.www.model.data.Data;

public class Platform extends Model<Platform> {

	/**
	 * 
	 */
	private static final long serialVersionUID = -617069672688693663L;
	
	public static final Platform dao = new Platform();
	
	public Platform getCachePlatformById(int id) {
		String key = CacheKeyUtil.getPlatformKey(id);
		Platform p = RedisUtil.get(key);
	
		if(p==null) {
			p = findById(id);
			RedisUtil.set(key, p);
		}
		return p;
	}

	/**
	 * 每日成交排行榜
	 * @param time
	 * @param pid
	 * @return
	 */
	public List<Platform> getVolume(String time,Integer pid){
		if(pid==42){
			String sql = "SELECT p.platform_name as platform_name,w.volume as volume FROM wd_new_data w,wd_p_platform p,wd_d_provinces pr WHERE w.platform_id=p.platform_id and p.province_id=pr.provinces_id and w.data_date=? GROUP BY p.platform_id order by volume desc limit 10";
			return find(sql,time);
		}else if(pid==28){
			String sql = "SELECT p.platform_name as platform_name,w.volume as volume FROM wd_new_data w,wd_p_platform p,wd_d_provinces pr WHERE w.platform_id=p.platform_id and p.province_id is null and w.data_date=? GROUP BY p.platform_id order by volume desc limit 10";
			return find(sql,time);
		}
		else{
			String sql = "SELECT p.platform_name as platform_name,w.volume as volume FROM wd_new_data w,wd_p_platform p,wd_d_provinces pr WHERE w.platform_id=p.platform_id and p.province_id=pr.provinces_id and w.data_date=? and pr.provinces_id=?  GROUP BY p.platform_id order by volume desc limit 10";
			return find(sql,time,pid);
		}
	}
	public List<Platform> getIndexList(){
		
		String sql=" select * from wd_p_platform platform , wd_p_hot_platform hotplatform , wd_p_img imgplatform  , wd_new_data wddata where platform.platform_id = hotplatform.platform_id and  platform.platform_id = imgplatform.platform_id  and platform.platform_id = wddata.platform_id limit 0,9";
		/**
		 select *
		 
		 from wd_p_platform platform , wd_p_hot_platform hotplatform , wd_p_img imgplatform
		 where platform.platform_id = hotplatform.platform and  platform.platform_id = imgplatform.platform_id
		 limit 0,10
		 */
		
		
		return find(sql);
		
	
	}
}
